package org.study;

import cn.hutool.core.lang.Console;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.*;
import org.study.entity.UserFormate;

import java.io.IOException;
import java.io.InputStream;

/**
 * Hello world!
 */
public class App {
    public static void main(String[] args) throws IOException {
        InputStream resourceAsStream = null;
        try{
            resourceAsStream = Resources.getResourceAsStream("mybatis-config.xml");
            SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(resourceAsStream);

           try( SqlSession sqlSession = factory.openSession()){
               UserFormate userFormate = sqlSession.selectOne("org.study.mapper.UserFormateMapper.selectOne",1);
               RowBounds rowBounds = new RowBounds(1, 1);
               Console.log(sqlSession.selectList("org.study.mapper.UserFormateMapper.list",null,rowBounds));
               System.out.println(userFormate);
           }catch (Exception e){
               e.printStackTrace();
           }

        }catch (Exception e) {
            System.out.println("异常....");
            e.printStackTrace();
        }finally {
            if(resourceAsStream!=null){
                resourceAsStream.close();
            }
            System.out.println("结束");
        }


    }
}
